package com.js.purs.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.js.purs.mapper.PurAvoidExpertMapper;
import com.js.purs.domain.PurAvoidExpert;
import com.js.purs.service.IPurAvoidExpertService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 回避专家列表Service业务层处理
 *
 * @author lzq
 * @date 20240706
 */
@Service
public class PurAvoidExpertServiceImpl implements IPurAvoidExpertService {
    @Autowired
    private PurAvoidExpertMapper purAvoidExpertMapper;

    /**
     * 查询回避专家列表
     *
     * @param expertCode 回避专家列表主键
     * @return 回避专家列表
     */
    @Override
    public PurAvoidExpert selectPurAvoidExpertByExpertCode(String expertCode) {
        return purAvoidExpertMapper.selectPurAvoidExpertByExpertCode(expertCode);
    }

    /**
     * 查询回避专家列表列表
     *
     * @param purAvoidExpert 回避专家列表
     * @return 回避专家列表
     */
    @Override
    public List<PurAvoidExpert> selectPurAvoidExpertList(PurAvoidExpert purAvoidExpert) {
        return purAvoidExpertMapper.selectPurAvoidExpertList(purAvoidExpert);
    }

    /**
     * 新增回避专家列表
     *
     * @param purAvoidExpert 回避专家列表
     * @return 结果
     */
    @Override
    public int insertPurAvoidExpert(PurAvoidExpert purAvoidExpert) {
        purAvoidExpert.setCreateTime(DateUtils.getNowDate());
        return purAvoidExpertMapper.insertPurAvoidExpert(purAvoidExpert);
    }

    /**
     * 修改回避专家列表
     *
     * @param purAvoidExpert 回避专家列表
     * @return 结果
     */
    @Override
    public int updatePurAvoidExpert(PurAvoidExpert purAvoidExpert) {
        return purAvoidExpertMapper.updatePurAvoidExpert(purAvoidExpert);
    }

    /**
     * 批量删除回避专家列表
     *
     * @param avoidIds 需要删除的回避专家列表主键
     * @return 结果
     */
    @Override
    public int deletePurAvoidExpertByAvoidIds(Long[] avoidIds) {
        return purAvoidExpertMapper.deletePurAvoidExpertByAvoidIds(avoidIds);
    }

    /**
     * 删除回避专家列表信息
     *
     * @param expertCode 回避专家列表主键
     * @return 结果
     */
    @Override
    public int deletePurAvoidExpertByExpertCode(String expertCode) {
        return purAvoidExpertMapper.deletePurAvoidExpertByExpertCode(expertCode);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deletePurAvoidExpertByBindCode(List<PurAvoidExpert> purAvoidExpert) {
        int index = 0;
        if (purAvoidExpert.size() > 0) {
            PurAvoidExpert expert = purAvoidExpert.get(0);
            index = purAvoidExpertMapper.deletePurAvoidExpertByBindCode(expert.getBindCode());
            for (PurAvoidExpert avoidExpert : purAvoidExpert) {
                index = purAvoidExpertMapper.insertPurAvoidExpert(avoidExpert);
            }
        }


        return index;
    }
}
